package com.wsq.animation

import android.animation.ValueAnimator
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import com.wsq.animation.animation.MyEvaluator
import com.wsq.animation.animation.MyInterpolator

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)


    }

    /**
     * 属性动画的第一种形式：
     * 通过ValueAnimation来配置属性值的变化
     */
    fun valueAnimationMethod1(){

        var valueAnimator = ValueAnimator.ofObject(MyEvaluator(), 0, 1000)
        valueAnimator.interpolator = MyInterpolator()
//        valueAnimator.setEvaluator(MyEvaluator<Int>())
        valueAnimator.duration = 1000
        valueAnimator.addUpdateListener(object: ValueAnimator.AnimatorUpdateListener{
            /**
             *
             * Notifies the occurrence of another frame of the animation.
             *
             * @param animation The animation which was repeated.
             */
            override fun onAnimationUpdate(animation: ValueAnimator?) {
                //animation?.getAnimatedValue()的值为估值器返回的值
                Log.e("获取ValueAnimation的值", (animation?.getAnimatedValue() as Float).toString())

                //我们可以通过估值器的返回值，来设置View的属性，以达到属性值变更的目的
                //例：textView.setX(animation?.getAnimatedValue())
            }

        })

        valueAnimator.start()
    }
}